package com.huatai.exchange.receive;

import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.AbstractService;
import com.huatai.exchange.dal.model.ExcFileLoadInfo;
import com.huatai.exchange.utils.VelocityContextHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.util.List;
import java.util.Map;

public abstract class AbstractFileDataReceiveService extends AbstractService implements FileDataReceiveService {

    @Autowired
    protected VelocityContextHelper velocityHelper;

    /**
     * @param srcPath  获取地址，邮箱， smb地址， http URL ftp 地址
     * @param srcName  获取文件匹配名称
     * @param markName 文件结束传输标志
     * @param resvMap  其他参数
     * @return 返回 下载号的文件列表， 方便存储及 解析入库
     */
    abstract List<String> findAndDownloadFileList(String srcPath, String srcName, String markName,String fileSuffix, String tmpDirPath,Map<String, Object> resvMap) throws BusinessException;

    @Override
    public List<String> receiveMessage(ExcFileLoadInfo loadInfo,  String tmpDirPath,Map<String, Object> resvMap) throws BusinessException {

        String srcPath = formatStr(loadInfo.getSrcPath(), resvMap);// 目标H地址
        String srcName = formatStr(loadInfo.getSrcName(), resvMap);// 目标名称
        String markName = formatStr(loadInfo.getMarkName(), resvMap);  //传输标志

        new File(tmpDirPath).mkdir();
        logger.info("查找参数：srcPath{}，srcName{}，markName{}，Suffix{}，tmpDirPath{}",srcPath,srcName,markName,loadInfo.getFileSuffix(),tmpDirPath);
        return  findAndDownloadFileList(srcPath, srcName, markName,loadInfo.getFileSuffix(),tmpDirPath, resvMap);
    }


}
